<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/10
 * Time: 15:48
 */

namespace app\models;

use yii;
use yii\db\Query;

class RepoFeeVerify extends BaseModel
{
    public function __construct()
    {
        $this->table = yii::$app->db->tablePrefix . 'repo_fee_verify';
    }

    public function one($where = [])
    {
        // TODO: Implement one() method.
        $db = new Query();
        $db->select('*')->from($this->table);
        if (!empty($where['id'])) $db->andWhere(['id' => $where['id']]);
        return $db->limit(1)->one();

    }

    public function queryOne($field, $where = [])
    {
        $db = new Query();
        $db->select($field)->from($this->table);
        if (!empty($where['id'])) $db->andWhere(['id' => $where['id']]);

        return $db->one();
    }

    public function all($where = [], $offset = false, $limit = false, $order = false)
    {
        $db = new Query();
        $db->select('*')->from($this->table);
        if (!empty($where['is_delete'])) $db->andWhere(['is_delete' => $where['is_delete']]);
        if (!empty($where['verify'])) $db->andWhere(['verify' => $where['verify']]);
        if ($order) $db->orderBy($order);
        if ($offset) $db->offset($offset);
        if ($limit) $db->limit($limit);
        return $db->all();
    }

    public function size($where)
    {
        $db = new Query();
        $db->select('count(*) as num')->from($this->table);
        if (!empty($where['is_delete'])) $db->andWhere(['is_delete' => $where['is_delete']]);
        if (!empty($where['verify'])) $db->andWhere(['verify' => $where['verify']]);

        $re = $db->one();
        return $re ? $re['num'] : 0;
    }

}